from pymongo import MongoClient
class Stu:
    def __init__(self):
        self.client = MongoClient('127.0.0.1',27017)
        self.db = self.client['test']

    def getClient(self,name):
        print(self.client,name)
    # 创建集合
    def createColl(self,coll_name):
        try:
            self.db.create_collection(coll_name)
        except Exception as err:
            print(f"创建集合出错:{err}")
    
    # 删除集合 改写这段代码 使其抛出异常
    def dropColl(self,coll_name):
        try:
            self.db.drop_collection(coll_name)
        except Exception as e:
            print(f"删除集合出错{e}")


# 主函数
if __name__ == '__main__':
    # 类的调用
    stu = Stu()
    stu.getClient('胡小婷')
    stu.dropColl("tta")
    stu.dropColl("tta")